<div class="layui-container fly-marginTop fly-user-main">
    {include file="common/menu" /}

    <div class="site-tree-mobile layui-hide">
        <i class="layui-icon">&#xe602;</i>
    </div>
    <div class="site-mobile-shade"></div>

    <div class="site-tree-mobile layui-hide">
        <i class="layui-icon">&#xe602;</i>
    </div>
    <div class="site-mobile-shade"></div>


    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user" id="LAY_msg" style="margin-top: 15px;">
            <!-- <button class="layui-btn layui-btn-danger" id="LAY_delallmsg">清空全部消息</button> -->
            <div id="LAY_minemsg" style="margin-top: 10px;">
                <!--<div class="fly-none">您暂时没有最新消息</div>-->
                <ul class="mine-msg">
                    {foreach $commentlist as $item }
                    <li data-id="123">
                        <blockquote class="layui-elem-quote">
                            <a href="{$item['userid'] == $userid ? url('home/user/index') : url('home/user/index',['userid'=>$item['userid']])}"
                                target="_blank">
                                <cite> {$item.user['nickname']}</cite>
                            </a>
                            回答了{$item.post['userid']['username']}的求解
                            <a target="_blank" href="{:url('home/index/info',['postid'=>$item.post['id']])}">
                                <cite>{$item.post['title']}</cite>
                            </a>
                        </blockquote>
                        <p>
                            <span>{$item['createtime']}</span>
                            <a href="javascript:;" class="layui-btn layui-btn-small layui-btn-danger fly-delete"
                                data-id="{$item['id']}">删除</a>
                        </p>
                    </li>
                    {/foreach}

                    <!-- <li data-id="123">
                        <blockquote class="layui-elem-quote">
                            系统消息：欢迎使用 layui
                        </blockquote>
                        <p><span>1小时前</span><a href="javascript:;"
                                class="layui-btn layui-btn-small layui-btn-danger fly-delete">删除</a></p>
                    </li> -->
                </ul>
                {$pagestr}
            </div>
        </div>
    </div>

</div>
<script>
    layui.use('layer', function () {
        var layer = layui.layer
        var $ = layui.jquery
        $(".fly-delete").click(function () {
            var postid = $(this).data('id')

            layer.confirm('是否确认删除', {
                icon: 3,
                title: '提示'
            }, function (index) {
                //关闭弹框
                layer.close(index)
                $.ajax({
                    type: 'POST',
                    url: `{:url('home/post/deletecommet')}`,
                    data: `postid=${postid}`,
                    dataType: 'json',
                    success: function (data) {
                        if (data.result) {
                            //成功
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function () {
                                location.href = "{:url('home/post/comment',['setup'=>4])}"
                                return false
                            })
                        } else {
                            //删除失败
                            layer.msg(data.msg)
                        }
                    }
                })

            })
        })

        // 清空全部信息
        // 批量删除
        function delAll() {
            var ids = tableCheck.getData()
            layer.confirm('确认要删除吗？', function (index) {
                //将数组转换为字符串
                var data = ids.join(',');
                del(data)
            })
        }

        // 单个删除
        function deletes(id) {
            layer.confirm('确认要删除吗？', function (index) {
                layer.close(index);
                del(id)
            })
        }

        // 调用删除方法
        function del(data) {
            //序列化 将对象转换为参数形式
            var params = {
                ids: data
            }

            params = $.param(params)

            $.ajax({
                type: "POST",
                url: `{:url('admin/config/del')}`,
                data: params,
                dataType: "json",
                success: function (data) {
                    layer.msg(data.msg, { icon: 5, time: 1000 }, function () {
                        location.reload()
                    })
                }
            })
        }
        $('#LAY_delallmsg').click(function () {
            layer.confirm('是否确认删除', {
                icon: 3,
                title: '提示'
            }, function (index) {
                //关闭弹框
                layer.close(index)
                $.ajax({
                    type: 'POST',
                    url: `{:url('home/post/deletecommet')}`,
                    data: `deleteall=true`,
                    dataType: 'json',
                    success: function (data) {
                        if (data.result) {
                            //成功
                            layer.msg(data.msg, {
                                icon: 1,
                                time: 2000 //2秒关闭（如果不配置，默认是3秒）
                            }, function () {
                                location.href = "{:url('home/post/comment',['setup'=>4])}"
                                return false
                            })
                        } else {
                            //删除失败
                            layer.msg(data.msg)
                        }
                    }
                })

            })
        })
    })
</script>